package com.atguigu.rabbitmq.workqueue;

import com.atguigu.rabbitmq.utlis.RabbitMQUtils;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.Scanner;

/**
 * 向rabbitmq中发送消息
 */
@SuppressWarnings("all")
public class Tasker extends Thread {

    private String taskID;

    private final String QUEUE_NAME = "HELLO";

    private final Scanner scanner = new Scanner(System.in);


    public Tasker(String taskID) {
        this.taskID = taskID;
    }

    @Override
    public void run() {
        Channel channel = RabbitMQUtils.getChannel();

        while (scanner.hasNext()) {
            String message = scanner.next();

            try {
                channel.queueDeclare(QUEUE_NAME, false, false, false, null);

                channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}



















